package com.shzu.jwc.ty.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.shzu.jwc.ty.bean.SystemStudytime;
import com.shzu.jwc.ty.bean.SystemStudytimeExample;
import com.shzu.jwc.ty.common.Page;
import com.shzu.jwc.ty.common.ReadExcelStyTime;
import com.shzu.jwc.ty.common.Semester;
import com.shzu.jwc.ty.dao.SystemStudytimeMapper;

@Service
public class Studytimeservice {

	@Autowired
	SystemStudytimeMapper mapper;
	
	@Autowired
	SystemYearservice systemYearservice;
	
	public Integer countstudytime() {
		return (int) mapper.countstudytime(systemYearservice.getoneyearby(Semester.getnow()));
	}
	
	public List<SystemStudytime> getStudytime(Page page){
		
		return mapper.getstudytime(systemYearservice.getoneyearby(Semester.getnow()), page.getStartPos(), page.getPageSize());
	}
	
	public List<String> getcollege(){
		return mapper.getcollege();
	}
	
	public List<Integer> getyear(){
		return mapper.getyear();
	}
	
	public List<SystemStudytime> searchstudytime(String userStudentInfoName){
		SystemStudytimeExample example=new SystemStudytimeExample();
		SystemStudytimeExample.Criteria criteria=example.createCriteria();
		criteria.andSystemYearIdEqualTo(systemYearservice.getoneyearby(Semester.getnow()));
		criteria.andUserStudentInfoNameLike("%"+userStudentInfoName+"%");
		return mapper.selectByExample(example);
	}
	
	public void batchImport(String name,MultipartFile file) {
		ReadExcelStyTime readExcel=new ReadExcelStyTime();
		List<SystemStudytime> systemStudytimes=readExcel.getExcelInfo(name, file);
		if(systemStudytimes.size()!=0) {
			for(Integer i=0;i<systemStudytimes.size();i++)
			{
				systemStudytimes.get(i).setSystemYearId(systemYearservice.getoneyearby(Semester.getnow()));
				mapper.insertstudytime(systemStudytimes.get(i));
			}
		}
	}

	public Integer byStuNumGetStuTime(String stuNum){
		return  (int)mapper.getStuTime(stuNum);
	}
}
